      <form action="<?php echo url::base() ?>articles/edit_add/<?php echo $articles->id ?>"  enctype="multipart/form-data" method="post">
      <section id="content">
        <div id="content-left-box">
          <div class="content-left">
            <h2>Články</h2>
            <ul class="menu">
              <li><a href="<?php echo url::base(); ?>articles/add" title="přidat nový článek">Přidat článek</a></li>
              <li><a href="<?php echo url::base(); ?>articles/my" title="Moje články">Moje články</a></li>
            </ul>
            <div class="content-left-bottom menu-left-bottom"></div>
          </div>
          <?php if ( empty($articles->published)): ?>
          <div class="content-left">
            <h2>Kategorie</h2>
            <div class="content-left-main">
              <?php
              $in_array = array();
              foreach($articles->articles_category->find_all() as $cat_in) {
               $in_array[] = $cat_in->id;
              }
              ?>
              <?php foreach($art_cat as $item): ?>
              <label><input type="checkbox" name="categories[]" <?php if (in_array($item->id, $in_array)) {echo 'checked="checked"';} ?> value="<?php echo $item->id ?>" class="text" /><?php echo $item->name ?></label>
              <?php endforeach ?>
                <input type="text" name="new_category" value="" class="text" />
                <a href="javascript:;" id="articles-cat-add" class="float-right button-dark" title="">Přidat kategorii</a>
            </div>
            <div class="content-left-bottom"></div>
          </div>
          <?php endif ?>
        </div>
        <div class="content-right">
          <header>
            <h2>Upravit článek</h2>
          </header>
          <section>
          <div id="big">
            <?php if (! empty($articles->published)): ?>
              Tento článek byl publikován a není možné ho již změnit.
            <?php else: ?>
            <fieldset>
              <ul class="big">
                <li>
                  <label for="title">Nadpis:</label>
                  <input id="title" type="text" name="title" value="<?php echo $articles->title ?>" class="text" />
                </li>
                <li>
                  <label for="seo_title">SEO url:</label>
                  <input id="seo_title" type="text" name="seo_title" value="<?php echo $articles->seo_title ?>" class="text" />
                </li>
                <li>
                  <label for="preview">Úvodní fotografie ke článku:</label>
                  <div class="text">
                    <input type="text" id="file-name" class="transp" readonly="readonly">
                      <input type="button" value="Vybrat soubor" class="file-input-button" />
                      <input type="file" name="filedata" class="file-input-hidden" onchange="javascript: document.getElementById('file-name').value = this.value" />
                  </div>
                </li>
                <li>
                  <label for="tinymce">Text:</label>
                  <div class="text">
                    <textarea cols="10" rows="10" id="tinymce" name="text" class="transparent"><?php echo $articles->text ?></textarea>
                  </div>               
                  <span class="button-textarea float-right"><a href="javascript:;" onmousedown="tinyMCE.get('tinymce').hide();">HTML</a></span>
                  <span class="button-textarea float-right"><a href="javascript:;" onmousedown="tinyMCE.get('tinymce').show();">Editor</a></span>
                  <span class="button-textarea float-right"><a id="img-add" href="<?php echo url::base(); ?>files/upload_img" title="">Nahrát obrázek</a></span>
                </li>
                <li>
                  <label for="tags">Tagy:</label>
                  <div id="container-tags" class="text">
                    <input id="tags" type="text" name="tags" value="" class="transp" />
                    <span class="top-right"><a href="javascript:;" id="articles-tag-add" class="float-right button-dark" title="">+</a></span>
                  </div>
                  <script>
                    $(function() {
                      $( "#dialog-confirm" ).hide();
                    });

                    function tagDelete(number,id) {
                      $( "#dialog-confirm" ).dialog({
                        resizable: false,
                        width: 400,
                        minHeight: 40,
                        modal: true,
                        draggable: false,
                        closeOnEscape: true,
                        open: function(event, ui) { $(".ui-dialog-titlebar-close,.ui-dialog-titlebar").remove(); },
                        buttons: {
                          "Odstranit": function() {
                            $.post("/articles/delete_tag/", { article_id: <?php echo $articles->id ?>, tag_id: id });
                            $('#article-tag'+number+'').remove();
                            $( this ).dialog( "close" );
                          },
                          "Zavřít": function() {
                            $( this ).dialog( "close" );
                          }
                        }
                      });
                    }
                  </script>
                  <div id="dialog-confirm">
                    <p>Skutečně chcete tento tag odtranit?</p>
                  </div>
                  <?php $i = 123456; foreach ($articles->articles_tag->find_all() as $item): ?>
                    <label class="text-tags" id="article-tag<?php echo $i; ?>">
                      <input type="hidden" value="<?php echo $item->tag; ?>" name="article_tags[]" readonly="readonly"><?php echo $item->tag; ?>
                      <a title="Odstranit" class="href-gray" onclick="tagDelete(<?php echo $i; ?>,<?php echo $item->id; ?>)" href="javascript:;">(x)</a>
                    </label>
                  <?php $i++; endforeach ?>
                </li>
                <li>
                  <input class="float-right" type="submit" name="form-submit" value="Upravit článek"  />
                </li>
              </ul>
            </fieldset>
            <?php endif ?>
            </div>
          </section>
          <div class="content-right-bottom"></div>
        </div>
      </section>
      </form>
      <script type="text/javascript">
        $(document).ready(function() {
          
          tinyMCE.init({
            // General options
            mode : "textareas",
            language : "cs",
            height : "200",
            convert_urls : true,
            relative_urls : false,
            remove_script_host : false,
            document_base_url : "<?php echo url::base(); ?>",

            // General options
            theme : "advanced",
            skin: "pv_skin",
            inlinepopups_skin: "pv_skin",
            theme_advanced_resizing_max_width : 440,
            theme_advanced_resizing_min_height : 200,

            plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

            // Theme options
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,forecolor,removeformat",
            theme_advanced_buttons2 : "bullist,numlist,outdent,indent,blockquote,sub,sup,|,link,unlink,image,cite,acrony,table,charmap,media,|,undo,redo,fullscreen,preview",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,

            // Drop lists for link/image/media/template dialogs
            external_image_list_url : "/files/upload_img_view/"
          });
          


          var cache = {}, lastXhr;
          $( "#tags" ).autocomplete({
            minLength: 1,
            source: function( request, response ) {
              var term = request.term;
              if ( term in cache ) {
                response( cache[ term ] );
                return;
              }

              lastXhr = $.getJSON( "<?php echo url::base(); ?>ajax/search_tag", request, function( data, status, xhr ) {
                cache[ term ] = data;
                if ( xhr === lastXhr ) {
                  response( data );
                }
              });
            }
          });

          var $loading = $('<img src="loading.gif" alt="loading" class="loading">');

          $('a#img-add').click(function(e) {
            e.preventDefault();
            var $this = $(this);
            var horizontalPadding = 30;
            var verticalPadding = 30;
            $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({
                title: ($this.attr('title')) ? $this.attr('title') : 'Nahrát obrázek',
                autoOpen: true,
                width: 770,
                height: 700,
                modal: true,
                resizable: true,
                autoResize: true
            }).width(800 - horizontalPadding).height(600 - verticalPadding);
        });

      });
    </script>